package com.ruoyi.xyh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xyh.domain.SupplyDemand;
import com.ruoyi.xyh.service.ISupplyDemandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供求信息Controller
 * 
 * @author ruoyi
 * @date 2024-03-26
 */
@RestController
@RequestMapping("/xyh/supplyd")
public class SupplyDemandController extends BaseController
{
    @Autowired
    private ISupplyDemandService supplyDemandService;

    /**
     * 查询供求信息列表
     */
    @PreAuthorize("@ss.hasPermi('xyh:supplyd:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupplyDemand supplyDemand)
    {
        startPage();
        List<SupplyDemand> list = supplyDemandService.selectSupplyDemandList(supplyDemand);
        return getDataTable(list);
    }

    /**
     * 导出供求信息列表
     */
    @PreAuthorize("@ss.hasPermi('xyh:supplyd:export')")
    @Log(title = "供求信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupplyDemand supplyDemand)
    {
        List<SupplyDemand> list = supplyDemandService.selectSupplyDemandList(supplyDemand);
        ExcelUtil<SupplyDemand> util = new ExcelUtil<SupplyDemand>(SupplyDemand.class);
        util.exportExcel(response, list, "供求信息数据");
    }

    /**
     * 获取供求信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('xyh:supplyd:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(supplyDemandService.selectSupplyDemandById(id));
    }

    /**
     * 新增供求信息
     */
    @PreAuthorize("@ss.hasPermi('xyh:supplyd:add')")
    @Log(title = "供求信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SupplyDemand supplyDemand)
    {
        return toAjax(supplyDemandService.insertSupplyDemand(supplyDemand));
    }

    /**
     * 修改供求信息
     */
    @PreAuthorize("@ss.hasPermi('xyh:supplyd:edit')")
    @Log(title = "供求信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SupplyDemand supplyDemand)
    {
        return toAjax(supplyDemandService.updateSupplyDemand(supplyDemand));
    }

    /**
     * 删除供求信息
     */
    @PreAuthorize("@ss.hasPermi('xyh:supplyd:remove')")
    @Log(title = "供求信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(supplyDemandService.deleteSupplyDemandByIds(ids));
    }
}
